package com.jsh.erp.service.bomMaterial;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jsh.erp.datasource.entities.BomMaterial;
import com.jsh.erp.datasource.mappers.BomMaterialMapper;
import com.jsh.erp.service.bom.BomService;
import com.jsh.erp.service.material.MaterialService;
import com.jsh.erp.service.materialExtend.MaterialExtendService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

/**
 *
 */
@Service
public class BomMaterialService extends ServiceImpl<BomMaterialMapper, BomMaterial> {

    @Resource
    private BomService bomService;

    @Resource
    private MaterialService materialService;

    @Resource
    private MaterialExtendService materialExtendService;

    public void removeForBomId(Long bomId) {
        remove(new QueryWrapper<BomMaterial>().eq("bom_id", bomId));
    }

    public List<BomMaterial> listByBomId(Long bomId) {
        return list(new QueryWrapper<BomMaterial>().eq("bom_id", bomId));
    }

    /**
     * 是否存在该无效关联的bom
     *
     * @param materialIds
     * @return
     */
    public boolean existByMaterialId(Collection<Long> materialIds) {
        return count(new QueryWrapper<BomMaterial>().in("material_id", materialIds)) > 0;
    }

    /**
     * 根据barcode获取
     *
     * @param barCode
     * @return
     */
    public List<BomMaterial> getByBomBarCode(Long bomId, String barCode) {
        return query().eq("bom_id", bomId).eq("bar_code", barCode).list();
    }

    /**
     * 根据barcode获取
     *
     * @param barCode
     * @return
     */
    public List<BomMaterial> getByBarCode(String barCode) {
        return query().eq("bar_code", barCode).list();
    }
}




